home *** CD-ROM | disk | FTP | other *** search
/ Shareworld 7 / Shareworld 7 (Disk 2 of 2).adf / SW7MachineLang.Examples / MLExampleSW7.asm < prev    next >
Assembly Source File  |  1978-02-07  |  3KB  |  110 lines

  1.     ;An example program to show the use of the BTST, the ASL, the AND,
  2.     ;the LSL, the LSR, and the OR commands.
  3.     ;Published with ShareWorld 7 - by Matthew Goode 27/9/96
  4.     ;Try to work out how everything works, explanations will be given
  5.     ;next time. An important skill to develope is being able to read
  6.     ;other peoples code, and understand it.
  7.     ;Note:Uses non-op friendly code, which should not be practised in real
  8.     ;programs (IE:DON'T use memory address directly!). Also the loops used
  9.     ;here are bad because they suck up processor time (and don't run at
  10.     ;the same speed on all Amigas).
  11.  
  12. ; -------------------------------------------------------------------
  13. ; ---------------------------Constants-------------------------------
  14.  
  15.  
  16. backgroundColourLoc    =    $dff180
  17. buttonInfoLoc        =    $bfe001
  18.  
  19. ; -------------------------------------------------------------------
  20. ; -------------------------Main program------------------------------
  21.  
  22.  
  23. Start
  24.     Move.l #100000,d0
  25.     Move.l #4,d1
  26.     Bsr MultiplyLong
  27.  
  28.     Cmp.l #400000,d2
  29.     Bne noFlash    ;Just checking that the routine works
  30.     Bsr StrobeRedYellow
  31.     ;Bsr StretchedStrobeBlue ;Try this one later
  32. noFlash
  33.     move.l #0,d0    ;Set no error condition code
  34.     Rts
  35.  
  36. ; -------------------------------------------------------------------
  37. ; -------------------------Sub-routines------------------------------
  38.  
  39. MultiplyLong
  40.     ; A simple routine to take two long values (in d0,d1) and
  41.     ;return (in d2) the product of these two values. 
  42.     ;Altered: d1,d2,d3
  43.  
  44.     Move.w #0,d3    ;D3 will become a 'bit counter'
  45.     Move.l #0,d2
  46. loopML1
  47.     Btst d3,d0    
  48.     beq NoSet    ;Is bit 'd2' set?
  49. Set
  50.     Add.l d1,d2
  51. NoSet
  52.     Asl.l #1,d1    ;Multiply d1 by 2
  53.     Add.w #1,d3
  54.     Cmp.w #32,d3    ;Have we checked every bit?
  55.     Bne loopML1
  56.     Rts
  57.     
  58. ; -------------------------------------------------------------------
  59.  
  60. StrobeRedYellow
  61.     ;Will strobe the background colour through various shades of green
  62.     ;until the mouse button is pushed.
  63.     ;An example of the And command, and shifting.
  64.     ;Altered:d0,d1
  65.  
  66.     Move.w #0,d0    ;Our counter
  67. loopSRY1
  68.     Add.w #1,d0
  69.     And.w #%1111,d0    ;Increment our counter, keeping it within the
  70.             ;range of 0-15
  71.     Move.w d0,d1    ;Move d0 to workspace
  72.     Lsl.w #4,d1    ;Shift value to 'green' area of an RGB value
  73.             ;(bits 0-3 are blue, 4-7 are green, and 8-11 are red)
  74.     Or.w #%111100000000,d1    ;Set Red component to full
  75.     Move.w d1,backgroundColourLoc    ;Set Background colour
  76.     Btst #6,buttonInfoLoc    ;Here we are testing the bit in memory that tells
  77.             ;us information about the state of the left mouse
  78.             ;button.
  79.             ;If the bit is set it means the button is NOT pushed
  80.     Bne loopSRY1
  81.     Rts
  82.  
  83. ; -------------------------------------------------------------------
  84.  
  85. StretchedStrobeBlue
  86.     ;Will strobe the background colour through various shades of blue
  87.     ;until the mouse button is pushed.
  88.     ;The pattern is streched out more that with StrobeGreen, try and
  89.     ;see why? (Again explained next time).
  90.     ;An example of the And command, and shifting.
  91.     ;Altered:d0,d1
  92.  
  93.     Move.w #0,d0    ;Our counter
  94. loopSSB1
  95.     Add.w #1,d0    ;Increment our counter.
  96.  
  97.     Move.w d0,d1    ;Move d0 to workspace
  98.     Lsr.w #8,d1    ;Shift to make d0 much smaller (will only change every
  99.             ;256 times this loop execute)
  100.     And.w #%1111,d1    ;Increment our counter
  101.             ;(bits 0-3 are blue, 4-7 are green, and 8-11 are red)
  102.     Move.w d1,backgroundColourLoc    ;Set Background colour
  103.     Btst #6,buttonInfoLoc    ;Here we are testing the bit in memory that tells
  104.             ;us information about the state of the left mouse
  105.             ;button.
  106.     Bne loopSSB1
  107.     Rts
  108.  
  109.  
  110.